package com.rankeiot.core.data;

import com.rankeiot.core.util.castor.*;

import java.util.Date;

public interface ValueGetter<V> {
    V get(Object key);
    default String getStr(Object key) {
        Object s = this.get(key);
        return s != null ? s.toString() : null;
    }
    default Long getLong(Object key) {
        return LongCastor.instance.cast(get(key));
    }
    default Integer getInteger(Object key) {
        return IntCastor.instance.cast(get(key));
    }
    default Boolean getBoolean(Object key){
        return BooleanCastor.instance.cast(get(key));
    }
    default Double getDouble(Object key){
        return DoubleCastor.instance.cast(get(key));
    }
    default Float getFloat(Object key) {
        return FloatCastor.instance.cast(get(key));
    }
    default Date getDate(Object key){
        return DateCastor.instance.cast(get(key));
    }
    default Boolean isTrue(Object key) {
        return BooleanCastor.instance.cast(get(key));
    }
    default boolean notNull(Object key) {
        return this.get(key) != null;
    }
    default boolean isNull(Object key) {
        return this.get(key) == null;
    }
}
